package router

import (
	"github.com/dchest/captcha"
	"github.com/gin-contrib/sessions"
	"github.com/gin-gonic/gin"
	"log"
	"testGin/controllers"
)

/*
  前台路由
 */
func IndexRouter(r *gin.Engine)  {

	//首页
	r.GET("/", controllers.IndexController{}.Login)
	//获取验证码接口
	r.GET("/system/index/captcha", func(c *gin.Context) {

		id := captcha.NewLen(4)
		session := sessions.Default(c)
		session.Set("code",id)
		session.Save()

		c.Header("Content-Type", "image/png")
		if err := captcha.WriteImage(c.Writer, id, 200, 80); err != nil {
			log.Println("show captcha error", err)
		}
	})
	//系统信息
	r.GET("/system/index/info", controllers.IndexController{}.Info)
	//系统信息
	r.POST("/system/index/info_ajax", controllers.IndexController{}.InfoAjax)
	//登录
	r.GET("/system/index/login", controllers.IndexController{}.Login)
	r.GET("/system/index/logout", controllers.IndexController{}.Logout)
	//登录验证
	r.POST("/system/index/login_ajax", controllers.IndexController{}.LoginAjax)
	//系统首页
	r.GET("/system/index/index", controllers.IndexController{}.Show)
	//配置接口
	r.GET("/system/index/init", controllers.IndexController{}.Init)
	//console
	r.GET("/system/index/console", controllers.IndexController{}.Console)

	//节点首页 -----------------------------------------------------------------
	r.GET("/system/node/index", controllers.NodeController{}.Index)
	//列表
	r.GET("/system/node/list", controllers.NodeController{}.GetList)
    //添加
	r.GET("/system/node/add", controllers.NodeController{}.Add)
	//保存
	r.POST("/system/node/add_ajax", controllers.NodeController{}.AddAjax)
	//修改
	r.GET("/system/node/edit", controllers.NodeController{}.Edit)
	//修改保存
	r.POST("/system/node/edit_ajax", controllers.NodeController{}.EditAjax)
	//删除
	r.GET("/system/node/del", controllers.NodeController{}.Del)
	//修改状态
	r.GET("/system/node/status", controllers.NodeController{}.Status)
	//排序
	r.GET("/system/node/px", controllers.NodeController{}.Px)
	//日志首页
	r.GET("/system/log/index", controllers.LogController{}.Index)
	//日志列表
	r.GET("/system/log/list", controllers.LogController{}.GetList)

	//管理员列表 ------------------------------------------------------------
	r.GET("/admin/admin/index",controllers.AdminController{}.Index)
	//列表
	r.GET("/admin/admin/list", controllers.AdminController{}.GetList)
	//添加
	r.GET("/admin/admin/add", controllers.AdminController{}.Add)
	//保存
	r.POST("/admin/admin/add_ajax", controllers.AdminController{}.AddAjax)
	//修改
	r.GET("/admin/admin/edit", controllers.AdminController{}.Edit)
	//修改保存
	r.POST("/admin/admin/edit_ajax", controllers.AdminController{}.EditAjax)
	//删除
	r.GET("/admin/admin/del", controllers.AdminController{}.Del)
	//修改状态
	r.GET("/admin/admin/status", controllers.AdminController{}.Status)
	//排序
	r.GET("/admin/admin/px", controllers.AdminController{}.Px)
	//选择角色
	r.GET("/admin/admin/role", controllers.AdminController{}.Role)
	//选择保存角色
	r.POST("/admin/admin/role_ajax", controllers.AdminController{}.RoleAjax)

    //角色
	r.GET("/admin/role/index",controllers.RoleController{}.Index)
	//列表
	r.GET("/admin/role/list", controllers.RoleController{}.GetList)
	//添加
	r.GET("/admin/role/add", controllers.RoleController{}.Add)
	//保存
	r.POST("/admin/role/add_ajax", controllers.RoleController{}.AddAjax)
	//修改
	r.GET("/admin/role/edit", controllers.RoleController{}.Edit)
	//修改保存
	r.POST("/admin/role/edit_ajax", controllers.RoleController{}.EditAjax)
	//删除
	r.GET("/admin/role/del", controllers.RoleController{}.Del)
	//修改状态
	r.GET("/admin/role/status", controllers.RoleController{}.Status)
	//排序
	r.GET("/admin/role/px", controllers.RoleController{}.Px)
	//选择权限
	r.GET("/admin/role/auth", controllers.RoleController{}.Auth)
	//保存选择权限
	r.POST("/admin/role/auth_ajax", controllers.RoleController{}.AuthAjax)

	//用户列表
	r.GET("/user/user/index",controllers.UserController{}.Index)
	//列表
	r.GET("/user/user/list", controllers.UserController{}.GetList)
	//修改
	r.GET("/user/user/edit", controllers.UserController{}.Edit)
	//修改保存
	r.POST("/user/user/edit_ajax", controllers.UserController{}.EditAjax)
	//删除
	r.GET("/user/user/del", controllers.UserController{}.Del)
	//修改状态
	r.GET("/user/user/status", controllers.UserController{}.Status)
    //在线用户
	r.GET("/user/userOnline/index", controllers.UserController{}.Online)
	//在线列表
	r.GET("/user/userOnline/list", controllers.UserController{}.GetOnList)
	//在线列表
	r.GET("/user/useronline/del", controllers.UserController{}.OnlineDel)

	//api接口
	r.GET("/system/appi/index",controllers.AppiController{}.Index)
	//列表
	r.GET("/system/appi/list", controllers.AppiController{}.GetList)
	//添加
	r.GET("/system/appi/add", controllers.AppiController{}.Add)
	//保存
	r.POST("/system/appi/add_ajax", controllers.AppiController{}.AddAjax)
	//修改
	r.GET("/system/appi/edit", controllers.AppiController{}.Edit)
	//修改保存
	r.POST("/system/appi/edit_ajax", controllers.AppiController{}.EditAjax)
	//删除
	r.GET("/system/appi/del", controllers.AppiController{}.Del)
	//修改状态
	r.GET("/system/appi/status", controllers.AppiController{}.Status)
	//排序
	r.GET("/system/appi/px", controllers.AppiController{}.Px)

    //文件
	r.POST("/system/upload/add_ajax", controllers.UploadController{}.AddAjax)
	r.GET("/system/upload/index", controllers.UploadController{}.Index)
	r.GET("/system/upload/flist", controllers.UploadController{}.Flist)
	r.GET("/system/upload/list", controllers.UploadController{}.List)

    //应用导航
	r.GET("/system/nav/index",controllers.NavController{}.Index)
	//列表
	r.GET("/system/nav/list", controllers.NavController{}.GetList)
	//添加
	r.GET("/system/nav/add", controllers.NavController{}.Add)
	//保存
	r.POST("/system/nav/add_ajax", controllers.NavController{}.AddAjax)
	//修改
	r.GET("/system/nav/edit", controllers.NavController{}.Edit)
	//修改保存
	r.POST("/system/nav/edit_ajax", controllers.NavController{}.EditAjax)
	//删除
	r.GET("/system/nav/del", controllers.NavController{}.Del)
	//修改状态
	r.GET("/system/nav/status", controllers.NavController{}.Status)
	//排序
	r.GET("/system/nav/px", controllers.NavController{}.Px)

	//工具
	r.GET("/system/tool/index", controllers.ToolController{}.Index)


}